<?php

// +----------------------------------------------------------------------
// | Copyright (c) 2020 All rights reserved.
// +----------------------------------------------------------------------
// | User: Simony <1362229026@qq.com>
// | wechat: Shen86579595
// +----------------------------------------------------------------------
namespace app\admin\controller;

use app\admin\controller\Common;
use think\Db;

class Easemoblm extends Common
{
    /**
    * User:Simony
    * Function: 群列表
    * @return mixed
    */
    public function groupList()
    {
        //params
        $field = input('get.field','');
        $value = input('get.value','');
        $search_field = input('get.search_field','');
        $search_value = input('get.search_value','');

        //where
        $where = [];

        //judge
        if($field) $where[$field]=$value;
        if($search_field) $where[$search_field]=$search_value;

        //model
        $easemoblmGroupModel = model('common/easemoblm/EasemoblmGroup');

        //getData
        $list = $easemoblmGroupModel->getList($where, 10);

        //assign
        $this->assign('list', $list);
        $this->assign('page', $easemoblmGroupModel->page_info->render());
        return $this->fetch();
    }


    /**
    * User:Simony
    * Function: 群添加修改
    */
    public function  groupAdd(){
        //params
        $id = input('param.id/d', '');

        //model
         $easemoblmGroupModel = model('common/easemoblm/EasemoblmGroup');
        $data= $easemoblmGroupModel->getInfoByID($id);

        if($this->request->isAjax()){

            //post params
            $ajax_data = $this->request->post();
             /*$validate = validate('EasemoblmGroup');
             if (!$validate->check($ajax_data)) {
                return ['err' => $validate->getError()];
            }*/
            //judge
            if($id && !$data) ds_json_encode('err', '数据不存在');

            $res = $id ? $easemoblmGroupModel->edit(['id' => $id], $ajax_data) : $easemoblmGroupModel->add($ajax_data);
            $res ? ds_json_encode('ret', '操作成功') : ds_json_encode('err', '操作失败');
        }
        $this->assign('data',$data);
        return $this->fetch();
    }

}